# PC端中间件层, 所以关于PC端的请求都必须经过此中间件
from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect

class WebPC(MiddlewareMixin):
    def process_request(self, request):
        # 检查请求路径是否包含 /web/pc/
        if '/web/pc/' in request.path:
            if request.path == '/web/pc/login/':
                return None
            else:
                # 检查session中是否存在用户信息
                if request.session.get('user'):
                    return None
                else:
                    return redirect('/web/pc/login/')
        return None

    def process_response(self, request, response):
        
        return response



